#ifndef FACEDETECT_H
#define FACEDETECT_H

#include <opencv2/opencv.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/core/core.hpp>
#include <memory>
#include <iostream>
#include "FaceDetect/face.hpp"

using namespace cv;
using namespace std;

//使用单例模式
class FaceDetect
{
private:
    static std::shared_ptr<FaceDetect> _detect;
    cv::CascadeClassifier faceCascade, eyeCascade;
    Ptr<face::FaceRecognizer> detectModel = face::EigenFaceRecognizer::create();
    FaceDetect() = default;
public:
    ~FaceDetect();
    //获取单例指针
    static std::shared_ptr<FaceDetect> getInstance() {
        if (_detect == nullptr)
            _detect = std::shared_ptr<FaceDetect>(new FaceDetect);
        return _detect;
    }
    /** @brief  设置面部识别器样本文件
    */
    static bool setFaceCascadeFile(const std::string& fileName) {
        if (_detect == nullptr)
            _detect = std::shared_ptr<FaceDetect>(new FaceDetect);

        return _detect->faceCascade.load(fileName);
    }
    /** @brief 设置眼睛识别器样本文件
    */
    static bool setEyeCascadeFile(const std::string& fileName) {
        if (_detect == nullptr)
            _detect = std::shared_ptr<FaceDetect>(new FaceDetect);

        return _detect->eyeCascade.load(fileName);
    }
    /** @brief
    */
    static void setDetectModel(const std::string& fileName) {
        if (_detect == nullptr)
            _detect = std::shared_ptr<FaceDetect>(new FaceDetect);
        _detect->detectModel->read(fileName);
    }
    /** @brief  检测并画出人脸，可选参数detectEye为是否识别眼睛
    */
    static int detectFaceAndDraw( Mat& img,
                       double scale, bool detectEye = false );
private:
    static int facePredict(const Mat& src_image);  //识别图片
};

#endif // FACEDETECT_H
